define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'membes/index' + location.search,
                    add_url: 'membes/add',
                    edit_url: 'membes/edit',
                    // del_url: 'membes/del',
                    // multi_url: 'membes/multi',
                    // import_url: 'membes/import',
                    table: 'membe_s',
                }
            });
            

         
        
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'membe_id',
                sortName: 'membe_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'pic', title: __('Pic'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        
                        {field: 'dream_id', title: __('dream_id'), operate: 'LIKE'},
                        {field: 'bg_image', title: __('Bg_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'status', title: __('封禁状态'), searchList: {"0":__('已封禁'),"1":__('未封禁')}, formatter: Table.api.formatter.status},
                        {field: 'dj_is', title: __('冻结状态'), searchList: {"0":__('未冻结'),"1":__('已冻结')}, formatter: Table.api.formatter.status},
                        {field: 'up_time', title: __('最后更新时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        
                        {field: 'operate', title: __('修改'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        
                        {
                        field: 'buttons',
                        width: "120px",
                        title: __('状态'),
                        table: table,
                        events: Table.api.events.operate,
                        buttons: [
                            {
                                name: 'detail',
                                text: __('冻结操作'),
                                title: __('冻结操作'),
                                classname: 'btn btn-xs btn-warning btn-dialog',
                                icon: 'fa',
                                visible: function(row){
                                        if(row.status != 5){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                },
                                url: 'membefreeze/index/index?a=1',
                                callback: function (data) {
                                    $(".btn-refresh").trigger("click");
          
                                    Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                }
                            },
                            // {
                            //     name: 'ajax',
                            //     text: __('封禁操作'),
                            //     title: __('封禁操作'),
                            //     classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                            //     icon: 'fa',
                            //     url: 'order/edit?mtype=2',
                            //     confirm: '是否确认完成订单，完成订单后，订单金额将直接返回',
                            //     success: function (data, ret) {
                            //              $(".btn-refresh").trigger("click");
                            //         //如果需要阻止成功提示，则必须使用return false;
                            //         //return false;
                            //     },
                            //     visible: function(row){
                            //             if(row.status != 5){
                            //                 return true;
                            //             }else{
                            //                 return false;
                            //             }
                            //     },
                            //     error: function (data, ret) {
                            //         console.log(data, ret);
                            //         Layer.alert(ret.msg);
                            //         return false;
                            //     }
                            // }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
